package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.AppUserMassageT;
import com.panshi.service.impl.AppUserMassageTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户站内消息表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-04
 */
@RestController
public class AppUserMassageTController {

    @Autowired
    private AppUserMassageTServiceImpl appUserMassageTService;

    @ApiOperation("用户ID查询用户 站内信息")
    @GetMapping("/app-user-massage-t/getUserMassage/{userId}/{page}")
    public List<AppUserMassageT> getUserMassage(@PathVariable int userId,@PathVariable int page){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<AppUserMassageT> pageParam = new Page<>(page, 3);
        QueryWrapper<AppUserMassageT> w = new QueryWrapper<>();
        w.eq("user_id",userId);
        w.eq("msg_type","1");
        appUserMassageTService.page(pageParam,w);

        List<AppUserMassageT> userPageAll = pageParam.getRecords();
        return userPageAll;
    }


    @ApiOperation("站内信息确认")
    @GetMapping("/app-user-massage-t/userMsgStatus/{id}")
    public Boolean userMsgStatus(@PathVariable int id){
        AppUserMassageT appUserMassageT = new AppUserMassageT();
        appUserMassageT.setId(id);
        appUserMassageT.setMsgStatus("1");
        return appUserMassageTService.updateById(appUserMassageT);
    }

}

